package translate;

import symbol.Symbol;
import util.BoolList;

public class Level {
	frame.Frame frame;
	public AccessList formals = null;
	public Level parent;
	public int depth;
	
	public Level(Level p, Symbol name, BoolList fmls) {
		if (p != null) depth = p.depth + 1;
			else depth = 0;
		parent = p;
		if (p == null)
			frame = new mips.Frame(new temp.Label("t_main"), fmls);
		else
			frame = new mips.Frame(new temp.Label(), fmls);
		AccessList tail = null;
		for (mips.AccessList a = (mips.AccessList) frame.formals; a != null; a = a.tail) {
			if (formals == null)
				formals = tail = new AccessList(new Access(this, a.head), null);
			else {
				tail.tail = new AccessList(new Access(this, a.head), null);
				tail = tail.tail;
			}
		}
	}
	
	public Level(frame.Frame f) {
		frame = f;
	}
	
	public Access allocLocal(boolean escape) {
		return new Access(this, frame.allocLocal(escape));
	}
	
	public temp.Label getFunLabel() {
		return frame.name;
	}
}
